package com.jblv.frame.web.config.JsonConfig;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

/**
 * @author happyonion.yangtao
 * @version 1.0
 * @title MyNullArrayJsonSerializer
 * @projectName jblv-frame
 * @packageName com.jblv.frame.user.service.config.JsonConfig
 * @description MyNullArrayJsonSerializer 处理数组类型的null值
 * @date Create at 2020/5/20 22:10
 * @since jdk1.8
 */
public class MyNullArrayJsonSerializer extends JsonSerializer {

    @Override
    public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
        if (value == null) {
            jgen.writeStartArray();
            jgen.writeEndArray();
        }
    }
}